/*
  自定义AppBar
  实现PreferredSizeWidget
 */

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: MyAppBar(child: Text('MyAppBar'), height: 150,),
    ),
  ));
  // 修改状态栏颜色，与appbar颜色相同
  SystemChrome.setSystemUIOverlayStyle(
     SystemUiOverlayStyle(
       systemNavigationBarColor: Color(0xFF000000),
       systemNavigationBarDividerColor: null,
       systemNavigationBarIconBrightness: Brightness.light,
       statusBarColor: Colors.white,
       statusBarIconBrightness: Brightness.dark,
       statusBarBrightness: Brightness.light,
     )
  );
}


class MyAppBar extends StatelessWidget implements PreferredSizeWidget{

  final Widget child;

  final double height;

  const MyAppBar({
    Key? key,
    required this.child,
    required this.height,
  }): super(key: key);


  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Container(
          child: this.child,
          color: Colors.amberAccent,
          height: this.height,// 高度设置
        )
    );
  }

  @override
  Size get preferredSize => Size.fromHeight(height);
}



